package com.zhdl.modules.common.protocol_param.service.impl;

import com.project.network.entity.PortComm;
import com.project.network.entity.PortSocket;
import com.project.network.entity.Protocols;
import com.project.network.repository.ProtocolsRepository;
import com.project.network.service.PortCommService;
import com.project.network.service.PortSocketService;
import com.zhdl.modules.common.protocol_param.service.ProtocolParamService;
import com.zhdl.modules.common.protocol_param.service.dto.PortCommQueryCriteria;
import com.zhdl.modules.common.protocol_param.service.dto.PortSocketQueryCriteria;
import lombok.extern.slf4j.Slf4j;
import org.springframework.data.domain.Page;
import org.springframework.data.domain.Pageable;
import org.springframework.stereotype.Service;

import javax.annotation.Resource;
import java.util.List;
import java.util.UUID;

@Slf4j
@Service
public class ProtocolParamServiceImpl implements ProtocolParamService {


    @Resource
    private PortCommService portCommService;

    @Resource
    private PortSocketService portSocketService;

    @Resource
    private ProtocolsRepository protocolsRepository;

    @Override
    public Protocols saveProtocolsDict(Protocols protocols) {
        return protocolsRepository.save(protocols);
    }

    @Override
    public PortComm savePortCommDict(PortComm portComm) {
        String id = UUID.randomUUID().toString();
        id = id.substring(0, 8);
        portComm.setId(id);
        return portCommService.insert(portComm);
    }

    @Override
    public PortSocket savePortSocketDict(PortSocket portSocket) {
        String id = UUID.randomUUID().toString();
        id = id.substring(0, 8);
        portSocket.setId(id);
        return portSocketService.insert(portSocket);
    }

    @Override
    public PortComm updatePortCommDict(PortComm portComm) {
        return portCommService.update(portComm, portComm.getId());
    }

    @Override
    public PortSocket updatePortSocketDict(PortSocket portSocket) {
        return portSocketService.update(portSocket, portSocket.getId());
    }

    @Override
    public void deletePortCommDict(String id) {
        portCommService.deleteById(id);
    }

    @Override
    public void deletePortSocketDict(String id) {
        portSocketService.deleteById(id);
    }

    @Override
    public PortComm findPortCommById(String id) {
        return portCommService.selectById(id);
    }

    @Override
    public PortSocket findPortSocketById(String id) {
        return portSocketService.selectById(id);
    }

    @Override
    public List<PortComm> findAllProtocolComm() {
        return portCommService.selectAll();
    }

    @Override
    public List<PortSocket> findAllProtocolSocket() {
        return portSocketService.selectAll();
    }

    @Override
    public Page<PortComm> findAllProtocolCommByCondition(PortCommQueryCriteria queryCriteria, Pageable pageable) {
        return portCommService.findAllPage(queryCriteria, pageable);
    }

    @Override
    public Page<PortSocket> findAllProtocolSocketByCondition(PortSocketQueryCriteria queryCriteria, Pageable pageable) {
        return portSocketService.findAllPage(queryCriteria, pageable);
    }


}
